using Godot;
using Godot.NativeInterop;
using System;
using System.ComponentModel;
using System.Runtime;

public partial class ActorMenu : WindowBase
{
	// Called when the node enters the scene tree for the first time.
	private Godot.VBoxContainer btnContainer;
	private ActorHero parent;
	private int moveRange = 0;
	public override void init()
	{
		base.init();
		btnContainer = this.GetNode<VBoxContainer>("PanelContainer/MarginContainer/btnContainer");
	}

	public override void onShow()
	{
		base.onShow();
		Button moveBtn = new Button();
		moveBtn.Text = "移动";
		moveBtn.Pressed += OnClickMove;
		btnContainer.AddChild(moveBtn);

		Button attactBtn = new Button();
		attactBtn.Text = "攻击";
		attactBtn.Pressed += onAttact;
		btnContainer.AddChild(attactBtn);

		Button endRoundBtn = new Button();
		endRoundBtn.Text = "结束回合";
		endRoundBtn.Pressed += OnEndRound;
		btnContainer.AddChild(endRoundBtn);
		parent = (ActorHero)this.viewParamDict["parent"];

		SetPosition(new Vector2(parent.Position.X + 40, parent.Position.Y));
	}

	private void OnClickMove()
	{

		//展示可以移动范围

		//挂载地图
		var tileMap = (TileMapBase)SceneUtil.currentScene.GetChildOrNull<TileMap>(0);
		if (tileMap is not null)
		{
			if (!tileMap.CheckLayerIsShow(TileMapLayerName.CANWALK))
			{
				var beginPos = TileMapUtil.ChangePosToTile(parent.Position.X, parent.Position.Y);
				tileMap.ShowActorCanMoveTileRange(beginPos, parent);
			}
		}

		ViewManager.getInstance().close("ActorMenu");

	}

	private void onAttact()
	{
		GD.Print("噢噢噢噢，我打你了");
	}

	private void OnEndRound()
	{
		EventManager.getInstance().dispatchEvent(EventType.EVENT_END_GAME_ROUND);
		ViewManager.getInstance().close("ActorMenu");
	}

}
